package com.shop.shard.controller.rest.order;

import com.shop.shard.common.*;
import com.shop.shard.controller.assembler.order.OrderOrderAssembler;
import com.shop.shard.controller.command.order.OrderOrderCreateCommand;
import com.shop.shard.controller.command.order.OrderOrderUpdateCommand;
import com.shop.shard.entity.order.OrderOrder;
import com.shop.shard.vo.order.OrderOrderVO;
import com.shop.shard.service.order.OrderOrderService;
import com.shop.shard.manager.order.OrderOrderManager;
import com.shop.shard.mapper.order.OrderOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * @Description: 代码生成器自动生成
 * @author:
 * @Createed Date: 2019-8-16 10:06:57
 * @ModificationHistory: Who  When  What
 * ---------     -------------   --------------------------------------
 **/
@RestController
@RequestMapping("api/v1/order/orderOrder")
@Api(value = "orderOrderService", description = "orderOrder相关AIP")
public class OrderOrderRest  {

    @Autowired
    private OrderOrderMapper orderOrderMapper;
    @Autowired
    private OrderOrderService orderOrderService;
    @Autowired
    private OrderOrderManager orderOrderManager;


    @PostMapping("add")
    @ApiOperation(value = "add OrderOrder ", notes = "xxx")
    public InvokeResult add(@RequestBody @Valid OrderOrderCreateCommand command) {
        OrderOrder entity = OrderOrderAssembler.toOrderOrder(command);
        orderOrderService.addEntity(entity);
        return InvokeResult.success();
    }

    /**
    * delect OrderOrder by id
    * @return
    */
    @PostMapping("delete")
    @ApiOperation(value = "delect OrderOrder by id", notes = "xxx")
    public InvokeResult delete(Long id){
        orderOrderService.delete(id);
        return InvokeResult.success();
    }


    @PostMapping("update")
    @ApiOperation(value = "update OrderOrder by id", notes = "xxx")
    public InvokeResult update(@RequestBody @Valid OrderOrderUpdateCommand command) {
        OrderOrder entity = OrderOrderAssembler.toOrderOrder(command);
        orderOrderService.updateEntity(entity);
        return InvokeResult.success();
    }

    @GetMapping("detail")
    @ApiOperation(value = "get OrderOrder detail by id", notes = "xxx")
    public InvokeResult detail(@RequestParam() Long id) {
        OrderOrderVO vo = orderOrderManager.selectDetailVoById(id);
        return InvokeResult.success(vo);
    }

    @GetMapping("page")
    @ApiOperation(value = "get OrderOrder page ", notes = "xxx")
    public IPage<OrderOrderVO> page(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10")Integer pageSize){
        Page page = new Page(pageNum,pageSize);
        Map<String,Object> map=new HashMap<>(4);
        IPage<OrderOrderVO> iPage=  orderOrderManager.getPage(page,map);
        return iPage;
    }
}
